#!/usr/bin/python
#Math Bacon Beta
#version 0.3b
#it works ok. needs more cowbell
# http://code.google.com/p/brain-bacon/
#import the required libs.

import random;

#set up the main variables
playerScore = 0
totalProblems = 10
count = 0

#define functions

def division(): #obviously really simple at this point, I'm just trying to get this thing started
    a = random.randrange(20,40)
    b = random.randrange(1,20)
    try:
        answer = float(input(str(a) + " / " + str(b) + " is? "))
    except ValueError:
        answer = 'wrong'
        print("Input error");
    if answer != (a/b):
        print("\nWrong! Correct answer is " + str(a/b) + "\n")
        return 0 #get it wrong, no score for you
    else:
        print("\nCorrect!\n")
        return 1 #yay! you got it right, have a worthless point.

def multiplication(): #great function, it's so nice i'll use it thrice.-jsw2
    a = random.randrange(20,40)
    b = random.randrange(1,20)
    try:
        answer = float(input(str(a) + " * " + str(b) + " is? "))
    except ValueError:
        answer = 'wrong'
        print("Input error")
    if answer != (a*b):
        print("\nWrong! Correct answer is " + str(a*b) + "\n")
        return 0
    else:
        print("\nCorrect!\n")
        return 1

def addition(): 
    a = random.randrange(20,40)
    b = random.randrange(1,20)
    try:
        answer = float(input(str(a) + " + " + str(b) + " is? "))
    except ValueError:
        answer = 'wrong'
        print("Input error");
    if answer != (a+b):
        print("\nWrong! Correct answer is " + str(a+b) + "\n")
        return 0
    else:
        print("\nCorrect!\n")
        return 1

def subtraction(): 
    a = random.randrange(20,40)
    b = random.randrange(1,20)
    try:
        answer = float(input(str(a) + " - " + str(b) + " is? "))
    except ValueError:
        answer = 'wrong'
        print("Input error");
    if answer != (a-b):
        print("\nWrong! Correct answer is " + str(a-b) + "\n")
        return 0
    else:
        print("\nCorrect!\n")
        return 1

#main loop
print("\nPlease choose excersise:\n");  #main Menu, not as clever as the other one, but simple enough
choice = input("1::Addition\n2::Subtraction\n3::Multiplication\n4::Division\n5::Mixed\n\nEnter corisponding number>");
print("\n");

while count < totalProblems: #keeping it simple to stay away from cross-version issues
    if choice == '1':
        playerScore = playerScore + addition();
    elif choice == '2':
        playerScore = playerScore + subtraction();
    elif choice == '3':
        playerScore = playerScore + multiplication();
    elif choice == '4':
        playerScore = playerScore + division();
    elif choice == '5':
        ranExcersise = random.randrange(1,4);
        if ranExcersise == 1:
            playerScore = playerScore + addition();
        elif ranExcersise == 2:
            playerScore = playerScore + subtraction();
        elif ranExcersise == 3:
            playerScore = playerScore + multiplication();
        elif ranExcersise == 4:
            playerScore = playerScore + division();
    count = count+1
print("\nScoreCard\n=========\n");
print("Total problems: " + str(totalProblems));
print("Total correct : " + str(playerScore));
print("               ------");
print("\ndone");

# your move now :P
# i see your move and raise you a stable release. ^_^ jsw2
